import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;
import java.util.ArrayList;

public class queryVendorPart
{
    private Scanner scanner;
    private Connection con;
    private ConnectDb dCon;
    private String maker, tname, pnum;
    
    public queryVendorPart(Connection c, ConnectDb d)
    {
        this.con = c;
        this.dCon = d;
       
    }
        public ArrayList<String> queryMaker(){
          //  Scanner scanner = new Scanner(System.in);
        ArrayList<String> makes = new ArrayList<String>();
        String query = "SELECT MAKE FROM MAKER";
            
            try
            {          
                Statement stmnt = con.createStatement();
                ResultSet rs = stmnt.executeQuery(query);
                while(rs.next())
                    makes.add(rs.getString(1));
                
                /*System.out.println("Enter the part vendor: ");
                scanner = new Scanner(System.in);
                String maker = "'"+scanner.next()+"'";
                maker = maker.toUpperCase();
                queryTName(maker);*/
            }
            
            catch (SQLException ex) 
            {
            System.err.println(ex.getMessage());
            }
            return makes;
    }

    
    public ArrayList<String> queryTName(String maker)
    {
    	this.maker = maker;
        String query = "SELECT TNAME FROM MAKER WHERE MAKE='"+this.maker+"'";
        ArrayList<String> tnames = new ArrayList<String>();

        try
        {          
            Statement stmnt = con.createStatement();
            ResultSet rs = stmnt.executeQuery(query);
            String tName = "";
            while(rs.next())
            	//tnames.add(rs.getString(1));
                this.tname = rs.getString(1).trim();
            /*
            System.out.println("table name" + tName);
            queryPnum(maker, tName);*/
        }
        
        catch (SQLException ex) 
        {
        System.err.println(ex.getMessage());
        }
        return tnames;
    }
    
    public ArrayList<String> queryPnum()
    {
        String query = "SELECT P_NUMBER FROM "+ this.tname;
        ArrayList<String> pnums = new ArrayList<String>();

        try
        {          
            Statement stmnt = con.createStatement();
            ResultSet rs = stmnt.executeQuery(query);
            while(rs.next())
            	pnums.add(rs.getString(1));
            /*
                System.out.println(rs.getString(1));
            
            System.out.println("Enter the part number ");
            scanner = new Scanner(System.in);
            String pNum = "'"+scanner.next()+"'";
            pNum = pNum.toUpperCase();
            queryParts(pNum, tName);*/
        }
        
        catch (SQLException ex) 
        {
        System.err.println(ex.getMessage());
        }
        return pnums;
    }
    
    public ArrayList<String> queryParts(String pNum)
    {
        this.pnum = pNum;
        String query = "SELECT CORE,INHEAD,OUTHEAD,INCON,OUCON,TMOUNT,OILCOOL,PRICE,AMOUNT FROM " +
        		   this.tname + " WHERE P_NUMBER='"+this.pnum+"'";
        ArrayList<String> parts = new ArrayList<String>();
        String part = "";

        try
        {          
            Statement stmnt = con.createStatement();
            ResultSet rs = stmnt.executeQuery(query);
            while(rs.next())
            {
                for(int i = 1; i<10; i++)
                {
                part = part + " "+rs.getString(i) ;
                }
                
                parts.add(part);
                part="";
            }

        }
        
        catch (SQLException ex) 
        {
        System.err.println(ex.getMessage());
        }
        return parts;
    }
    /*
    public void queryRLink(String pNum, String tName)
    {
        String query = "Select RLINK from radCRX where ARS1=" + pNum + " OR ARS2=" + pNum+ " OR ARS3="+ pNum + " OR ARS4=" + pNum + " OR MOD1= "+ pNum +
            " OR MOD2="+ pNum + " OR MOD3="+ pNum + " OR MOD4="+ pNum + " OR BEH1="+ pNum + " OR BEH2="+ pNum + " OR BEH3="+ pNum + " OR BEH4="+ pNum + " OR DAN1="+ pNum
            + " OR DAN2="+ pNum + " OR DAN3="+ pNum + " OR DAN4="+ pNum;
        
        try
        {          
            Statement stmnt = con.createStatement();
            ResultSet rs = stmnt.executeQuery(query);
            String rLink = "";
            while(rs.next())
                rLink = "'" +rs.getString(1) + "'";
            
            rLink = rLink.toUpperCase();
            queryRLink(pNum);
        }
        
        catch (SQLException ex) 
        {
        System.err.println(ex.getMessage());
        }
    }
    */
}
